$package('YiYa.merchant');
YiYa.merchant = function(){
	var _box = null;
	var _this = {
		config:{
			event:{
				add:function(){
					$('#detail').css('display','none');
					_box.handler.add();
				},
				edit:function(){
					var selected = _box.utils.getCheckedRows();
					if ( _box.utils.checkSelectOne(selected)){
						var record = selected[0];
						_box.handler.edit();
						if(record.type.detail==1){
							$('#detail').css('display','block');
						}else{
							$('#detail').css('display','none');
						}
					}
				},
				view:function(){
					var selected = _box.utils.getCheckedRows();
					if ( _box.utils.checkSelectOne(selected)){
						var record = selected[0];
						_box.handler.view();
						if ( _box.utils.checkSelectOne(selected)){
							var record = selected[0];
							_box.handler.view();
							if(record.type.detail==1){
								$('#detail1').css('display','block');
							}else{
								$('#detail1').css('display','none');
							}
						}
					}
				}
			},
			dataGrid:{
				title:'开支列表',
				url:'dataList.do',
				columns:[[
				          {field:'id',checkbox:true},
				          {field:'title',title:'开支名目',width:120,sortable:true},
						  {field:'expense_date',title:'开支日期',width:80,sortable:true,
				        	  formatter:function(value,row,index){
				        		  if(row["expenseDate"]!=null){
				        		  return new Date(row["expenseDate"]).format("yyyy-MM-dd");
				        		  }
						  }},
						  {field:'type',title:'开支类型',width:80,sortable:true,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["type"]).name;
						  }},
						  {field:'amount',title:'金额',width:80,sortable:true},
						  {field:'e.create_time',title:'创建时间',width:120,sortable:true,
				        	  formatter:function(value,row,index){
				        		  return row["createTime"];
						  }},
						  {field:'e.update_time',title:'更新时间',width:120,sortable:true,
				        	  formatter:function(value,row,index){
				        		  return row["updateTime"];
						  }},
						  {field:'create_by',title:'创建人',width:120,
				        	  formatter:function(value,row,index){
				        		  return new Object(row["createBy"]).nickName;
						  }},
						  {field:'remark',title:'备注',width:120,
							  formatter:function(value,row,index){
								  if(value!=undefined){
									  if(value.length>10){
										  var str = value.substring(0,8);
										  return str.concat('......');	  
									  }
									  return value;
								  }
								  
						  }}
				          ]],
				          toolbar:[
				                   {id:'btnadd',text:'添加',btnType:'add'},
				                   {id:'btnedit',text:'编辑',btnType:'edit'},
				                   {id:'btndelete',text:'删除',btnType:'remove'},
				                   {id:'btnview',text:'查看',btnType:'view'}
				                   ]
			}
		},
		init:function(){
			$('.easyui-datebox').datebox({
			    formatter: function(date){ return date.getFullYear()+'-'+(date.getMonth()+1)+'-'+date.getDate();},
			    parser: function(date){ return new Date(Date.parse(date.replace(/-/g,"/")));}
			});
			$('#cc').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc1").combobox('clear');
			    	$.get("../expense_type/getId.do?id="+newValue,function(data,status){
			    	    if(data.data.detail==1){
			    	    	$('#detail').css('display','block');
			    	    }else{
			    	    	$('#detail').css('display','none');
			    	    }
			    	});
			    }
			});
			$('#cc2').combobox({
			    onChange:function(newValue,oldValue){
			    	$("#cc3").combobox('clear');
			    	$.get("../expense_type/getId.do?id="+newValue,function(data,status){
			    	    if(data.data.detail==1){
			    	    	$('#detail').css('display','block');
			    	    }else{
			    	    	$('#detail').css('display','none');
			    	    }
			    	});
			    }
			});
			_box = new YDataGrid(_this.config);
			_box.init();
		}
	}
	return _this;
}();

$(function(){
	YiYa.merchant.init();
});


